import { TOGGLE_SEND, SET_SEND ,SET_REFERRER, SET_APPID,SET_TIMESTAMP,SET_NONCESTR,SET_SIGNATURE} from "@/utils/constant/mutation-types.js";
const app = {
  namespaced: true,
  state: {
    send: false, //客户经理暂停派件设置（true|false)
    referrer: "",
    // 微信js-sdk配置信息
    appId:"",
    timeStamp:"", // 时间
    nonceStr:"", // 生成签名的随机字符串
    signature:""  // 签名
   
  },
  getters: {
    send: state => state.send,
    referrer: state => state.referrer,
    appId: state => state.appId,
    timeStamp: state => state.timeStamp,
    nonceStr: state => state.nonceStr,
    signature: state => state.signature
  },
  mutations: {
    [TOGGLE_SEND](state) {
      state.send = !state.send;
    },
    [SET_SEND](state, status) {
      state.send = Boolean(status);
    },
    [SET_REFERRER](state, status) {
      state.referrer = status;
    },
    [SET_APPID](state, status) {
      state.appId = status;
    },
    [SET_TIMESTAMP](state, status) {
      state.timeStamp = status;
    },
    [SET_NONCESTR](state, status) {
      state.nonceStr = status;
    },
    [SET_SIGNATURE](state, status) {
      state.signature = status;
    }
  },
  actions: {
    toggleSend({ commit }) {
      commit(TOGGLE_SEND);
    },
    setSend({ commit }, status) {
      commit(SET_SEND, status);
    },
    setReferrer({ commit}, status) {
      commit(SET_REFERRER, status);
    },
    setAppId({commit}, status) {
      commit(SET_APPID, status);
    },
    setTimeStamp({commit}, status) {
      commit(SET_TIMESTAMP, status);
    },
    setNonceStr({commit}, status) {
      commit(SET_NONCESTR, status);
    },
    setSignature({commit}, status) {
      commit(SET_SIGNATURE, status);
    },
    setConfig(
      {dispatch},
      {appId, timeStamp, nonceStr,signature } 
    ){
      dispatch("setAppId", appId);
      dispatch("setTimeStamp", timeStamp);
      dispatch("setNonceStr", nonceStr);
      dispatch("setSignature", signature);
    }
  }
};
export default app;
